package com.aptech.test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WriteCookies extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        Cookie c = new Cookie("username", request.getParameter("username"));
        c.setPath("/");
        c.setMaxAge(1000);
        response.addCookie(c);
        c = new Cookie("password", request.getParameter("password"));
        c.setPath("/");
        c.setMaxAge(1000);
        response.addCookie(c);

        request.setAttribute("message", "Cookies username and password have been added successfully.");
        request.getRequestDispatcher("/testCookie.jsp").forward(request, response);
    } 
}
